const app = getApp()
const api = app.globalData.api
Page({

  /**
   * 页面的初始数据
   */
  data: {
    minDate: new Date(1960,1,1).getTime(),
    radio: '男',
    birthDay: '', //生日
    workDate: '', //参加工作日期
    nation: '',
    education: '',
    marriage: '',
    politicsStatus: '',
    exSalary: '',
    exWorkPlace: '',
    homeTown:'',
    jobId:'',
    jobName:'',
    time_popup_show: false,
    timeType: '',
    optionType: '',
    typeOption: [],
    type_popup_show: false
  },
  
  commit(e) {
    let para = e.detail.value;
    para.education = this.data.education;
    para.birthDay = this.data.birthDay;
    para.nation = this.data.nation;
    para.workDate = this.data.workDate;
    para.marriage = this.data.marriage;
    para.politicsStatus = this.data.politicsStatus;
    para.exSalary = this.data.exSalary;
    para.exWorkPlace = this.data.exWorkPlace;
    para.homeTown = this.data.homeTown;
    para.jobId = this.data.jobId;

    api.curlPost('?cla=talentApp&fun=commitEdit', para).then((res) => {
      wx.redirectTo({
        url: '../success/success',
      })
    })
  },
  onRadioChange(event) {
    this.setData({
      radio: event.detail,
    });
  },

  /**选择时间 */
  chooseTime(e) {
    let type = e.currentTarget.dataset.type;
    let currentTimestamp = '';
    if (type == 'birthDay') {
      currentTimestamp = this.data.birthDay ? new Date(api.rowTocol(this.data.birthDay)).getTime() : new Date().getTime();
    } else if (type == 'workDate') {
      currentTimestamp = this.data.workDate ? new Date(api.rowTocol(this.data.workDate)).getTime() : new Date().getTime();
    }

    this.setData({
      timeType: type,
      time_popup_show: true,
      currentTimestamp: currentTimestamp
    })
  },
  /**日期选择确认 */
  timeConfirm(event) {
    let date = new Date(event.detail);
    let type = this.data.timeType;
    if (type == 'birthDay') {
      this.setData({
        birthDay: api.formatDateCRM('Y-m-d', date),
        time_popup_show: false,
      })
    } else if (type == 'workDate') {
      this.setData({
        workDate: api.formatDateCRM('Y-m-d', date),
        time_popup_show: false,
      })
    }


  },
  timeCancel(e) {
    this.setData({
      time_popup_show: false
    })
  },
  /**
   * 选择选项
   */
  chooseOption(e) {
    let type = e.currentTarget.dataset.type;
    api.curlPost('?cla=talentApp&fun=search', {
      type: type
    }).then((res) => {
      this.setData({
        optionType: type,
        type_popup_show: true,
        typeOption: res.data.option,
      })
    })

  },

  /**选择确认 */
  onTypeConfirm(event) {
    const {
      picker,
      value,
      index
    } = event.detail;
    switch (this.data.optionType) {
      case 'nation':
        this.setData({
          nation: value,
          type_popup_show: false
        })
        break;
      case 'education':
        this.setData({
          education: value,
          type_popup_show: false
        })
        break;
      case 'exWorkPlace':
        this.setData({
          exWorkPlace: value,
          type_popup_show: false
        })
        break;
      case 'exSalary':
        this.setData({
          exSalary: value,
          type_popup_show: false
        })
        break;
      case 'homeTown':
        this.setData({
          homeTown: value,
          type_popup_show: false
        })
        break;
      case 'marriage':
        this.setData({
          marriage: value,
          type_popup_show: false
        })
        break;
        case 'politicsStatus':
        this.setData({
          politicsStatus: value,
          type_popup_show: false
        })
        break;
        case 'jobId':
          console.log(value)
          this.setData({
            jobId: value.id,
            jobName:value.text,
            type_popup_show: false
          })
          break;
        default:
        break;

    }
    this.setData({
      type_popup_show: false
    })

  },
  onTypeCancel(e) {
    this.setData({
      type_popup_show: false
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})